//
//  SearchViewController.m
//  Coco_Music
//
//  Created by K。 on 15/6/19.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SearchViewController.h"
#import "SearchDetailsController.h"
#import "AFN_block.h"
#import "Search.h"

@interface SearchViewController ()

@property(nonatomic,retain)SearchDetailsController *searchDC;
@property(nonatomic,retain)NSMutableArray *array;
@property(nonatomic,retain)CloudView *clurd;

@end

@implementation SearchViewController

-(void)dealloc
{
    [self.mySearch release];
    [self.searchDC release];
    [self.array release];
    [self.clurd release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    self.mySearch =[[SearchView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.mySearch.backgroundColor =[UIColor whiteColor];
    self.mySearch.Mypresent = self;
    [self.view addSubview:self.mySearch];
    self.array = [NSMutableArray array];


    [_mySearch release];
    [self getEveryoneSearch];
}

-(void)getEveryoneSearch
{
    
    [AFN_block NSString:@"http://so.ard.iyyin.com/sug/billboard" Blokc:^(id request) {
       NSMutableArray *array = [request objectForKey:@"data"];
        for (NSMutableDictionary *dic in array) {
           NSString *name = [dic objectForKey:@"val"];
            [self.array addObject:name];
        }
        [self viewWillAppear:YES];
    }];
}

-(void)viewWillAppear:(BOOL)animated
{
    [self.clurd removeFromSuperview];

    self.clurd = [[CloudView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.origin.y+80, [UIScreen mainScreen].bounds.size.width, 350) andNodeCount:_array];
    self.clurd.delegate = self;
    [self.view addSubview:self.clurd];
    [self.clurd release];
   }


-(void)PresentDetailView
{
    self.searchDC = [[SearchDetailsController alloc]init];
    self.searchDC.title = self.mySearch.SearchTextField.text;
    [self.navigationController pushViewController:self.searchDC animated:YES];
    [self.searchDC release];
}

-(void)didSelectedNodeButton:(CloudButton *)button
{
     self.searchDC = [[SearchDetailsController alloc]init];
    self.searchDC.title = button.titleLabel.text;
     [self.navigationController pushViewController:self.searchDC animated:YES];
    [self.searchDC release];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
